/*
* @Author: Administrator
* @Date:   2018-01-10 11:00:20
* @Last Modified by:   Administrator
* @Last Modified time: 2018-01-27 15:17:23
*/
const path =  require('path')
const express = require('express')
const serverDev = require('./util/server_dev.js')
const serverDist = require('./util/server_dist.js')
const apiMiddle = require('./util/api_middle.js')
const isDev =  process.env.NODE_ENV === 'dev'
const app = express();


apiMiddle(app)


app.use(function (error, req, res, next) {
  if(error.response.data) {
    res.send(error.response.data).end()
    return
  } else {
    console.error(error)
  }
})
//  开发环境
if(isDev) {
  serverDev(app)
} else {
  // 生产环境
  serverDist(app)
}
const host = process.env.HOST || '0.0.0.0'
const port = process.env.PORT || 3333
app.listen(port, host, function() {
  console.log('启动成功')
})
